package com.jdbc.book.BookManagement;

import com.jdbc.book.Books.Book;

import java.util.Scanner;

public class BookManagement {

    public static void main(String[] args) {
            while (true){
                System.out.println("*****  欢迎进入书籍管理系统  *****");
                System.out.println("*****  1.添加图书信息  *****");
                System.out.println("*****  2.删除图书信息  *****");
                System.out.println("*****  3.修改图书信息  *****");
                System.out.println("*****  4.退出          *****");
                Scanner sc =new Scanner(System.in);
                System.out.println("*****  请输入你要进行的操作（1-4）：*****");

                String bookfunction = sc.nextLine();
                switch (bookfunction){
                    case "1":
                        addbook();
                        break;
                    case "2":
                        deletebook();
                        break;
                    case "3":
                        updatebook();
                        break;
                    case "4":
                        System.out.println("正在退出书籍管理");
                        System.exit(0);
                        break;
                    default:
                        System.out.println("输入错误，请重新输入！");
                }
            }
        }

        //添加图书
        public static void addbook(){
            Scanner sc=new Scanner(System.in);
            String name,aut,num;
            int id;
            System.out.println("请输入编号");
            id=sc.nextInt();
            System.out.println("请输入书名");
            Scanner sc1=new Scanner(System.in);
            name=sc1.nextLine();
            System.out.println("请输入作者");
            aut=sc1.nextLine();
            System.out.println("请输入数量");
            num=sc1.nextLine();
            System.out.println("请输入书籍类型");
            String type=sc1.nextLine();
            System.out.println("请输入出版社");
            String publisher=sc1.nextLine();
            System.out.println("请输入单价");
            int price=sc.nextInt();
            Book book= new Book(name, id, aut, num,type,publisher,price);
            BookDao dao=new BookDao();
            boolean flag=dao.addbook(book);
            if (flag){
                System.out.println("保存成功！");
            }else {
                System.out.println("保存失败！");
            }
        }


        //删除图书
        public static void deletebook(){
            Scanner sc=new Scanner(System.in);
            System.out.println("请输入删除图书的编号：");
            int delID =sc.nextInt();
            BookDao dao=new BookDao();
            boolean flag=dao.delbook(delID);
            if (flag){
                System.out.println("删除成功！");
            }else {
                System.out.println("删除失败！");
            }
        }


        //修改图书
        public static void updatebook(){
            Scanner sc=new Scanner(System.in);
            System.out.println("请输入修改图书的编号：");
            int updID=sc.nextInt();
            System.out.println("请输入书名");
            Scanner sc1=new Scanner(System.in);
            String name=sc1.nextLine();
            System.out.println("请输入作者");
            String aut=sc1.nextLine();
            System.out.println("请输入数量");
            String num=sc1.nextLine();
            System.out.println("请输入书籍类型");
            String type=sc1.nextLine();
            System.out.println("请输入出版社");
            String publisher=sc1.nextLine();
            System.out.println("请输入单价");
            int price=sc.nextInt();
            Book book=new Book(name,updID,aut,num,type,publisher,price);
            BookDao dao=new BookDao();
            boolean flag=dao.updatebook(book);
            if (flag){
                System.out.println("修改成功！");
            }else {
                System.out.println("修改失败！");
            }
        }
    }

